package top.makeprogress.taobaospider.util;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class ClassUtils {
	public static Map<String, Map<String, Field>> classFieldMap = new HashMap<String, Map<String, Field>>();

	public static <T> Map<String, Field> getAllFields(Class<? super T> c) {
		String className = c.getName();
		Map<String, Field> result = classFieldMap.get(className);
		if (result != null) {
			return result;
		}
		result = new HashMap<String, Field>();
	    while (c!= null){
			Field[] declaredFields = c.getDeclaredFields();
			for (Field field : declaredFields) {
				result.put(field.getName(), field);
			}
	        c= c.getSuperclass();
	    }
		classFieldMap.put(className, result);
		return result;
	}

}
